<template>
	<scroll ref="mescrollRef" @init="mescrollInit" :down="downOption" @down="downCallback" :up="upOption" @up="upCallback"
	 @emptyclick="emptyClick">
		<stop isBack>
			<view slot="content">选择考核</view>
		</stop>
	<!-- 	<view class="bcf">
			<view class="cu-btn line-green lg round" @tap="showSelectList = !showSelectList"> 选择</view>
			<job-selector :multi="false" :show="showSelectList" @onSelect="selectJob"></job-selector>
		</view> -->
	<!-- 	
		<view class="bcf pad3">
			<view class="list-style-1">选择考核目的</view>
		</view>
		<view>
			
		</view> -->
		<view class="bcf pad3">
			<view class="list-style-1">选择考核对象</view>
		</view>
		<view class="flex-r flex-wrap flex-start pad3 bcf">
			<view class="pad2 bdbdo flcc pos-r round2" :class="curUserId == row.id?'bcf':'bc13'"
			@tap="selectUser(row.id)"
			v-for="row in data" :key="log.id">
			<!-- @tap="goto('/pages/ciming/kpi/job_user_full_test?uid=' + row.id + '&jid=' + id)" -->
				<view class="wh20-20 round30 bdso ofh">
					<image :src="pic(row.pic)" mode="aspectFit" class="wh20-20 round30"></image>
				</view>
				<view class="flex1 mart1">{{row.name}}</view>
				<ripple></ripple>
				<view class="pos-a r0 b0 fa fa-check-circle-o c01 fa-2x" v-show="curUserId == row.id"></view>
			</view>
		</view>
		<view v-if="isbool(curUserId)">
			<view class="bcf pad3">
				<view class="list-style-1">该员工近期考核数据</view>
			</view>
			<view>
				<view class="flrc fs14 bcf mart3 pad3" v-for="item in userLogs" :key="item.id">
					<view class="flex1">第 [ {{item.term}} ] 期考核</view>
					<view class="">总分：{{item.score}}</view>
				</view>
				<view class="pad3 mar3 bcf tac bdda" v-if="userLogs.length == 0">
					暂无往期数据
				</view>
			</view>
		</view>
		<view class="pos-f b0 r0 l0 bcf pad3">
			<view class="cu-btn lg round line-green w100" @tap="startTest">
				开始考核
				<ripple></ripple>
			</view>
		</view>
		<loading :loading="myIsLoading"></loading>
	</scroll>
</template>

<script>
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	import List from '../../../assets/js/list.js'
	
	import jobSelector from '../../../templete/ciming/job_selector.vue'
	
	export default {
		mixins: [MescrollMixin],
		components:{jobSelector},
		data() {
			let list = new List()
			return {
				list,
				id:0,//岗位ID
				data: [],
				dataInfo:{},
				where: {
					eq: {
						"jobs.id": '',
						category: '',
						groups: '',
					}
				},
				search: "",
				src: "/api_/zones",
				//岗位选择器相关
				showSelectList:false,
				//用户选择数据
				curUserId:0,
				userLogs:[],
			}
		},
		methods: {
			reload() {
				this.showLoading()
				this.list.setData({
					_order: {
						sort: "ASC"
					},
					_where: this.where,
					_search: this.search,
					_g: ['user', 'job']
				}).reload()
			},
			selectJob(val){
				this.log(val)
			},
			selectUser(id){
				this.curUserId = id
				this.getUserTestLog()
			},
			startTest(){
				if(!this.$com.isbool(this.curUserId)){
					this.$com.showToast('请选择用户')
					return
				}
				this.$api.post('/api/kpiUserTests',{
					job:'/api_/jobs/' + this.id,
					user:'/api_/ciming_users/'+this.curUserId,
				},res=>{
					this.log(res)
					this.goto('/pages/ciming/kpi/job_user_full_test?test='+res.d.id)
				})
			},
			getUserTestLog(){
				if(this.$com.isbool(this.curUserId)){
					this.$api.get('/api/kpiUserTests',{
						_where:{
							eq:{
								job:this.id,
								user:this.curUserId,
							}
						}
					},res=>{
						this.log(res)
						this.userLogs = res.d
					})
				}
			}
		},
		mounted() {
			this.list.initMescroll(this).setUrl('/api/cimingUsers').setData({
				_order: {
					id: "ASC"
				},
				_where: this.where,
				_search: this.search,
				_g: ['user', 'job']
			}).setCbFunc(res => {
				this.data = res
				this.clearLoading()
			}).reload()
		},
		onLoad(option) {
			this.where.eq["jobs.id"] = this.id = option.job
			this.list.reload()
		},
		onShow() {
			this.getUserTestLog()
		}
	}
</script>

<style>

</style>
